package com.bitbakery.plugin.cl.lang.psi;

import com.bitbakery.plugin.cl.lang.CLElementVisitor;
import com.intellij.lang.ASTNode;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.tree.TokenSet;
import org.jetbrains.annotations.NotNull;

public class CLFormalParameterList extends CLElement {
    private static final TokenSet PARAMETER_FILTER = TokenSet.create(
            CLElementTypes.REGULAR_PARAMETER,
            CLElementTypes.OPTIONAL_PARAMETER,
            CLElementTypes.KEYWORD_PARAMETER,
            CLElementTypes.REST_PARAMETER);

    public CLFormalParameterList(final ASTNode node) {
        super(node);
    }

    public CLFormalParameter[] getParameters() {
        final ASTNode[] nodes = getNode().getChildren(PARAMETER_FILTER);
        final CLFormalParameter[] params = new CLFormalParameter[nodes.length];
        for (int i = 0; i < params.length; i++) {
            params[i] = (CLFormalParameter) nodes[i].getPsi();
        }
        return params;
    }

    public void accept(@NotNull PsiElementVisitor visitor) {
        if (visitor instanceof CLElementVisitor) {
            ((CLElementVisitor) visitor).visitCommonLispParameterList(this);
        } else {
            visitor.visitElement(this);
        }
    }

    public String toString() {
        return "CLFormalParameterList";
    }
}
